//
//  JFeedbackController.m
//  HeadIndustry
//
//  Created by jun on 2017/9/12.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JFeedbackController.h"


@interface JFeedbackController ()

@property (nonatomic, strong) UITextView *textView;

@end

@implementation JFeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    [super InitUI];
    if (_inputType == 0) {  //意见反馈
        self.titleLabel.text = @"意见反馈";
    }
    else //投诉店铺
    {
        self.titleLabel.text = @"投诉店铺";
    }
    
    self.leftButton.hidden = NO;
    self.rightButton. hidden = NO;
    [self.leftButton setImage:[UIImage imageNamed:backBtnImg] forState:UIControlStateNormal];
    self.leftButton.frame = CGRectMake(8, self.leftButton.frame.origin.y, 30, 30);
    
    [self.rightButton setTitle:@"发送" forState:UIControlStateNormal];
    [self.rightButton setTitleColor:kRGBColor(150, 150, 150) forState:UIControlStateNormal];
    self.rightButton.layer.borderColor = kRGBColor(60, 60, 60).CGColor;
    self.rightButton.layer.borderWidth = 0.5;
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(15, 15, kWindowW - 30 , CGRectGetHeight(self.contentView.frame) - 30)];
//    textView.backgroundColor = kRGBColor(245, 245, 245);
    textView.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:textView];
    _textView = textView;
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    if (_inputType == 0) {  //意见反馈
        placeHolderLabel.text = @"请输入您想反馈的宝贵意见";
    }
    else //投诉店铺
    {
        placeHolderLabel.text = @"反馈您投诉的内容";
    }
    
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = kRGBColor(206, 206, 210);
    [placeHolderLabel sizeToFit];
    [textView addSubview:placeHolderLabel];
    
    // same font
    textView.font = [UIFont systemFontOfSize:14];
    placeHolderLabel.font = [UIFont systemFontOfSize:14];
    
    [textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [_textView resignFirstResponder];
}


- (void)rightButtonClick:(UIButton *)rightButton
{
    if (_textView.text.length == 0) {
        [SVProgressHUD showErrorWithStatus:@"请输入内容"];
        return;
    }
    NSString *url;
    NSDictionary *dic;
    if (_inputType == 0) {  //意见反馈
        url = @"FeadBack/InsertFeadback";
        dic = @{@"Content":_textView.text,
                @"CreatedById":@([GLOBALDATA userInfoModel].CustomerId)};
    }
    else //投诉店铺
    {
        url = @"ShopComplaintApi/InsertShopComplaint";
        dic = @{@"Content":_textView.text,
                @"CreatedById":@([GLOBALDATA userInfoModel].CustomerId),
                @"ShopId":@(self.shopID),
                @"CustomerId":@([GLOBALDATA userInfoModel].CustomerId),
                @"UserId":@([GLOBALDATA userInfoModel].CustomerId)};
    }
    
    
    
    [JNetManager FeedBackRequedtUrl:url
                            Content:dic
                            success:^(id response) {
                                if ([response integerValue] == 1) {
                                    [SVProgressHUD showSuccessWithStatus:@"反馈成功"];
                                    [self.navigationController popViewControllerAnimated:YES];
                                }
                            } failure:^(NSString *err) {
                                [SVProgressHUD showErrorWithStatus:err];
                            }];
}

- (void)leftButtonClick:(UIButton *)leftButton
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
